<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/_fragments :: head(~{::title})">
    <title>博客管理</title>
</head>
<body>
<!--导航条-->
<nav th:replace="admin/_fragments :: menu(1)" class="ui m-bg segment attached m-padded-tb-mini animated fadeInDown m-shadow-small">
    <div class="ui container">
        <div class="ui secondary  stackable menu">
            <a href="#" class="item">
                <h1 class="ui header item m-text-thin" style="color: #ff8080">管理后台</h1>
            </a>
            <a href="#" class="item m-item m-pink m-mobile-hide"><i class="icon home m-pink"></i>博客</a>
            <a href="#" class="item m-item m-pink m-mobile-hide"><i class="idea icon m-pink"></i>分类</a>
            <a href="#" class="item m-item m-pink m-mobile-hide"><i class="tags icon m-pink"></i>标签</a>
            <a href="#" class="item m-item m-pink m-mobile-hide"><i class="linkify icon m-pink"></i>友链</a>
            <div class="right m-item menu m-pink m-mobile-hide">
                <div class="ui dropdown item">
                    <div class="text m-pink">
                        <img src="../../static/img/logo.jpg" class="ui avatar image" alt="">
                        wuhobin
                    </div>
                    <i class="icon dropdown m-pink"></i>
                    <div class="menu m-bg">
                        <a href="#" class="item">注销</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <a href="#" class="ui big menu toggle m-pink icon button m-right-top m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>
<div class="ui menu attached pointing m-bg animated fadeInDown">
    <div class="ui container">
        <div class="right mini menu">
            <a th:href="@{/admin/blogs/input}" class="item m-pink">发布</a>
            <a th:href="@{/admin/blogs}" class="item active m-pink">列表</a>
        </div>
    </div>
</div>
<!--中间内容-->
<div class="m-container-large m-padded-tb-big animated bounceInUp">
    <div class="ui container">
        <div  class="ui m-top-color form  segment  m-bg">
            <input type="hidden" name="page">
            <div class="fields  inline" style="margin-bottom: 5px">
                <div class="field">
                    <input type="text" name="title" placeholder="标题">
                </div>
                <div class="field">
                    <div class="ui labeled action input">
                        <div class="ui type selection  dropdown">
                            <input type="hidden" name="typeId">
                            <i class="icon dropdown"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div th:each="type : ${types}" class="item" data-value="1" th:data-value="${type.id}" th:text="${type.name}">java</div>
                            </div>
                        </div>
                        <button class="ui clear compact button mini basic">clear</button>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend"  name="recommend">
                        <label for="recommend" class="m-pink">推荐</label>
                    </div>
                </div>
                <div class="field">
                    <button type="button" id="search-btn" class="ui mini  basic button"><i class="search icon m-pink"></i>搜索</button>
                </div>
            </div>
        </div>
        <div id="table-container">
            <table class="ui table compact m-bg center aligned" th:fragment="blogList">
                <thead class="m-bg">
                <tr class="m-bg">
                    <th class="m-bg m-pink m-text-thin"></th>
                    <th class="m-bg m-pink m-text-thin">标题</th>
                    <th class="m-bg m-pink m-text-thin">分类</th>
                    <th class="m-bg m-pink m-text-thin">是否推荐</th>
                    <th class="m-bg m-pink m-text-thin">状态</th>
                    <th class="m-bg m-pink m-text-thin">更新时间</th>
                    <th class="m-bg m-pink m-text-thin">操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="blog,iterStat : ${page.content}">
                    <td th:text="${iterStat.count}">1</td>
                    <td th:text="${blog.title}">springboot</td>
                    <td th:text="${blog.type.name}">java</td>
                    <td th:text="${blog.recommend ? '是':'否'}">是</td>
                    <td th:text="${blog.published ? '发布':'草稿'}">是</td>
                    <td th:text="${blog.updateTime}">2020-1-28</td>
                    <td>
                        <a th:href="@{/admin/blogs/{id}/input(id=${blog.id})}" class="ui mini teal basic button ">编辑</a>
                        <a th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}" class="ui mini red basic button ">删除</a>
                    </td>
                </tr>
                </tbody>
                <tfoot class="m-bg">
                <tr class="m-bg">
                    <th colspan="7" class="m-bg">
                        <div class="ui mini pagination floated left  menu m-bg" th:if="${page.totalPages}>1">
                            <a onclick="page(this)" th:attr="data-page=${page.number}-1" class="item" th:unless="${page.first}">上一页</a>
                            <a onclick="page(this)" th:attr="data-page=${page.number}+1" class=" item" th:unless="${page.last}">下一页</a>
                        </div>
                        <a th:href="@{/admin/blogs/input}" class="ui mini right floated teal basic button">新增</a>
                    </th>
                </tr>
                </tfoot>
            </table>
        </div>
        <div class="ui success  message m-bg" th:unless="${#strings.isEmpty(message)}">
            <i class="close icon"></i>
            <div class="header">提示：</div>
            <p th:text="${message}"></p>
        </div>
    </div>
</div>
<!--/*/<th:block th:replace="admin/_fragments :: script">/*/-->
<!--/*/</th:block>/*/-->
</body>
</html>
<script>
    <!-- 移动端导航条   -->
    $(".toggle.menu").click(function (){
        $(".m-item").toggleClass("m-mobile-hide")
    })
    $(".ui.dropdown").dropdown({
        on:'hover'
    });
    function page(obj) {
        $("[name='page']").val($(obj).data("page"));
        loaddata();
    }
    $("#search-btn").click(function () {
        $("[name='page']").val(0);
       loaddata();
    });
    $(".clear.button").click(function () {
        $(".type.ui.dropdown").dropdown('clear')
    });
    function loaddata() {
        $("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search",{
            title : $("[name='title']").val(),
            typeId : $("[name='typeId']").val(),
            recommend : $("[name='recommend']").prop('checked'),
            page : $("[name='page']").val()
        });
    }

    $(".message .close").on('click',function () {
        $(this).closest(".message")
            .transition("fade");
    })

</script>